<?php
	$session = Mage::getSingleton('checkout/session');
	$lass_order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
	$model = Mage::getModel('enets/method_enets');
	// $quote = Mage::getModel('checkout/session')->getQuote();
	// $total = $quote->getGrandTotal();
	$enets_mid = $model->getConfigData('nets_mid');
	$merchant_cert_id = $model->getConfigData('merchant_cert_id');
	
	$order = Mage::getSingleton('sales/order');
	$order->loadByIncrementId($lass_order_id);
	$_totalData = $order->getSubtotal();
	$_grand = $_totalData['grand_total'];
	//print_r( $_totalData );
	
	//set POST variables
		$url = 'https://test.enets.sg/enets2/PaymentListener.do';
		$fields = array(
			'NetsMid'				=>$enets_mid,
			'SubmissionMode'		=>'B',
			'TxnAmount'				=>round ($_totalData, 2),
			'MerchantTxnRef'		=>$lass_order_id,
			'MerchantCertId'		=>$merchant_cert_id,
			'PaymentType'			=>'AUTH',			
			'SuccessUrl'			=>'https://gobblershop.com/magento/index.php/enets/payment/response/',			
			'SuccessUrlParams'		=>'order_id=' . $lass_order_id,			
			'FailureUrl'			=>'https://gobblershop.com/magento/index.php/enets/payment/failure/',			
			'FailureUrlparams'		=>'order_id=' . $lass_order_id,			
			'CancelUrl'				=>'https://gobblershop.com/magento/index.php/enets/payment/cancel/',			
			'CancelUrlParams'		=>'order_id=' . $lass_order_id,			
		);

		//url-ify the data for the POST
		foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
		rtrim($fields_string,'&');

		//open connection
		$ch = curl_init();

		//set the url, number of POST vars, POST data
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch,CURLOPT_POST,count($fields));
		curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

		//execute post
		$result = curl_exec($ch);

		//close connection
		curl_close($ch);
		
?>
<!--
<form name="cart" method="post" action="https://test.enets.sg/enets2/PaymentListener.do">
	<input type="hidden" name="NetsMid" value="<?php echo $enets_mid ?>">
	<input type="hidden" name="SubmissionMode" value="B">
	<input type="hidden" name="TxnAmount" value="<?php echo round ($_totalData, 2)?>">
	<input type="hidden" name="MerchantTxnRef" value="<?php echo $lass_order_id?>">
	<input type="hidden" name="MerchantCertId" value="<?php echo $merchant_cert_id ?>">	
	<input type="hidden" name="PaymentType" value="AUTH">
	<input type="hidden" name="SuccessUrl" value="https://gobblershop.com/magento/index.php/enets/payment/response/">
	<input type="hidden" name="SuccessUrlParams" value="order_id=<?php echo $lass_order_id ?>">
	<input type="hidden" name="FailureUrl" value="https://gobblershop.com/magento/index.php/enets/payment/failure/">
	<input type="hidden" name="FailureUrlparams" value="order_id=<?php echo $lass_order_id ?>">
	<input type="hidden" name="CancelUrl" value="https://gobblershop.com/magento/index.php/enets/payment/cancel/">
	<input type="hidden" name="CancelUrlParams" value="order_id=<?php echo $lass_order_id ?>">
	<input type="hidden" name="status" value="Y">
	<input type="submit">
</form>-->